package com.itheima.log;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.LogMapper;
import com.itheima.pojo.CheckItem;
import com.itheima.pojo.LogInfo;
import com.itheima.pojo.PageResult;
import com.itheima.pojo.QueryPageBean;
import com.itheima.service.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service(interfaceClass = LogService.class)
@Transactional
public class LogServiceImpl implements LogService {
    @Autowired
    LogMapper logMapper;

    @Override
    public void saveLog(LogInfo logInfo) {
        logMapper.saveLog(logInfo);
    }

    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        Page page = PageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
        List<LogInfo> list = new ArrayList<>();
        if (queryPageBean.getQueryString() == null || queryPageBean.getQueryString().trim() == "") {
            list = logMapper.findAll(null);
        } else {
            list = logMapper.findAll("%"+queryPageBean.getQueryString()+"%");
        }
        return new PageResult(page.getTotal(),list);
    }

    @Override
    public void deleteById(int id) {
        logMapper.deleteById(id);
    }
}
